<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/global.jsp" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>广东石油化工学院学生信息管理系统 - 评分</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="${path}/static/js/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${path}/static/css/admin.css"/>
</head>
<body>

<div class="layui-tab page-content-wrap">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
        <div class="layui-tab-item">
              <div class="layui-inline">
                        <select class="layui-select" id="selectCourseId" name="selectCourseId">
                            <option value="" selected disabled style="display: none;">请选择课程</option>
                            <c:forEach items="${courseList}" var="course">
                                <option value="${course.coursename}">${course.coursename}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <button class="layui-btn layui-btn-normal" onclick="findStudentSelectCourseByCourseId();">搜索
                    </button>
        </div>
        </div>
        <div class="layui-form">
                    <table class="layui-table" lay-skin="line">
                        <colgroup>
                            <col width="50">
                            <col class="hidden-xs" width="150">
                            <col class="hidden-xs" width="220">
                            <col class="hidden-xs" width="200">
                            <col class="hidden-xs" width="220">
                            <col class="hidden-xs" width="220">
                            <col width="200">
                            <col width="200">
                        </colgroup>
                        <thead>
                        <tr>
                            <th></th>
                            <th class="hidden-xs">学生学号</th>
                            <th class="hidden-xs">学生姓名</th>
                            <th class="hidden-xs">课程名称</th>
                            <th class="hidden-xs">学生平时分</th>
                            <th class="hidden-xs">考试分</th>
                            <th class="hidden-xs">总分</th>
                            <th class="hidden-xs">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${courseList}" var="course" varStatus="index">
                            <tr class="parent collapsed">
                                <td></td>
                                <td class="hidden-xs">${index.index + 1}</td>
                                <td class="hidden-xs">${course.studentid}</td>
                                <td>${course.coursename}</td>
                                <td>
                                    <c:choose>
                                        <c:when test="${course.usualgrades  == '-1.0'}">
                                            未评分
                                        </c:when>
                                        <c:otherwise>
                                            ${course.usualgrades}
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${course.examgrade  == '-1.0'}">
                                            未评分
                                        </c:when>
                                        <c:otherwise>
                                            ${course.examgrade}
                                        </c:otherwise>
                                    </c:choose>

                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${course.totalgrade  == '-1'}">
                                            未评分
                                        </c:when>
                                        <c:otherwise>
                                            ${course.totalgrade}
                                        </c:otherwise>
                                    </c:choose>

                                </td>
                                <td>
                                    <div class="layui-btn-group">
                                        <button type="button" class="layui-btn layui-btn-normal"
                                                onclick="updateStudentCourseGrade('${course.studentid}','${course.coursename}');">
                                            评分
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
    </div>
</div>
<div class="layui-row" id="studentCourseInfo" style="display: none;">
    <div class="layui-col-md10">
        <div class="layui-form-item" style="margin-top: 20px">
            <label class="layui-form-label">平时成绩</label>
            <div class="layui-input-block">
                <input type="text" name="usualgrades" id="usualgrades"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 20px">
            <label class="layui-form-label">考试成绩</label>
            <div class="layui-input-block">
                <input type="text" name="examgrade" id="examgrade"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 20px">
            <label class="layui-form-label">总成绩</label>
            <div class="layui-input-block">
                <input type="text" name="totalgrade" id="totalgrade"  class="layui-input">
            </div>
        </div>
    </div>
</div>


<script src="${path}/static/js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['form', 'element', 'jquery', 'layer'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer,
                element = layui.element;

        $("#usualgrades").blur(function(){//文档加载完毕后，监听失去焦点事件
            $('#totalgrade').val(
                (parseInt(parseFloat($('#usualgrades').val())*0.4) +
                (parseFloat($('#examgrade').val())*0.6))
            );
        });

        $("#examgrade").blur(function(){//文档加载完毕后，监听失去焦点事件
            $('#totalgrade').val(
                parseInt(parseFloat($('#usualgrades').val())*0.4 +
                parseFloat($('#examgrade').val())*0.6)
            );

        });
        /**
         *
         * 修改学生成绩
         **/
        window.updateStudentCourseGrade = function (res,res2) {
            $.ajax({
                type: "get",
                url: "${path}/user/getScById",
                data: {
                    'studentId': res,
                    'coursename':res2
                },
                dataType: 'json',
                success: function (response) {
                    if (response.success) {
                        $('#usualgrades').val(response.data.usualgrades == '-1' ? 0 : response.data.usualgrades);
                        $('#examgrade').val(response.data.examgrade == '-1' ? 0: response.data.usualgrades);
                        $('#totalgrade').val(response.data.totalgrade == '-1' ? 0: response.data.totalgrade);

                        layer.open({
                            type: 1,
                            title: "课程评分",
                            area: ['500px', '300px'],
                            content: $("#studentCourseInfo"),
                            btn: ['确定', '关闭'],
                            yes: function (index, layero) {
                                $.ajax({
                                    type: "post",
                                    url: "${path}/user/updateScoreByTeacherAndStudentId",
                                    data: {
                                        'coursename':res2,
                                        'studentId': res,
                                        'usualgrades': $('#usualgrades').val(),
                                        'examgrade': $('#examgrade').val(),
                                        'totalgrade': $('#totalgrade').val(),
                                    },
                                    dataType: 'json',
                                    success: function (response) {
                                        if (response.success) {
                                            layer.msg("评分成功", {offset: '60px', icon: 6, anim: 6, time: 1000});
                                            layer.close(index);
                                            location.reload();
                                        } else {
                                            layer.msg(res.msg, {offset: '60px', icon: 5, anim: 6, time: 3000});
                                        }
                                    },
                                    error: function (res) {
                                        layer.msg(res);
                                    }
                                });
                            },
                            btn2: function (index, layero) {
                                layer.close(index);
                            }
                        });
                    } else {
                        layer.msg(res.msg, {offset: '60px', icon: 5, anim: 6, time: 3000});
                    }
                },
                error: function (res) {
                    layer.msg(res);
                }
            });
        }




    })


</script>

</body>
</html>